<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragment::head(~{::title})">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta charset="UTF-8">
	<title>个人信息</title>
</head>

<body class="no-skin">

	<!--导航部分-->
	<div th:replace="_fragment :: nav"></div>

	<div class="main-container" id="main-container">
		<script type="text/javascript">
		try{ace.settings.check('main-container' , 'fixed')}catch(e){}
		</script>

		<!--侧边栏-->
		<div th:replace="_fragment :: menu(-1,-1)"></div>

		<div class="main-content" >
			<!--面包屑-->
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try {
						ace.settings.check('breadcrumbs', 'fixed')
					} catch (e) {
					}
				</script>

				<!--多级导航-->
				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a th:href="@{/admin/toIndex}">首页</a>
					</li>
					<li class="active">个人信息</li>
				</ul><!-- /.breadcrumb -->
			</div>

			<div class="page-content">
				<!--设置-->
<!--				<div th:replace="_fragment::setting"></div>-->

				<div class="page-content-area">
					<div class="page-header">
						<h1>
							用户个人信息
						</h1>
					</div><!-- /.page-header -->

					<div class="row">
						<div class="col-xs-12">
							<div class="">
								<div id="myUser-profile-2" class="myUser-profile">
								<div class="tabbable">
									<ul class="nav nav-tabs padding-18">
										<li class="active">
											<a data-toggle="tab" href="#home">
												<i class="green ace-icon fa fa-myUser bigger-120"></i>
												个人信息
											</a>
										</li>
									</ul>

									<div class="tab-content no-border padding-24">
										<div id="home" class="tab-pane in active">
											<div class="row">
												<div class="col-xs-12 col-sm-3 center">
													<span class="profile-picture">
														<img class="editable img-responsive" alt="未设置头像" id="avatar2" th:src="@{${myUser.headImage}}" style="width: 200px; height: 200px;"/>
													</span>

													<div class="space space-4"></div>

													<a href="javascript:void(0)" class="btn btn-sm btn-block btn-success">
														<i class="ace-icon fa fa-plus-circle bigger-120"></i>
														<span class="bigger-110">帅哥</span>
													</a>
												</div><!-- /.col -->

												<div class="col-xs-12 col-sm-9">
													<h4 class="blue">
														<span class="middle">登录状态</span>
														<span class="label label-purple arrowed-in-right">
															<i class="ace-icon fa fa-circle smaller-80 align-middle"></i>
															在线
														</span>
													</h4>

													<div class="profile-myUser-info">
														<div class="profile-info-row">
															<div class="profile-info-name"> 用户名 </div>

															<div class="profile-info-value">
																<span th:text="${myUser.loginMyUser}">张三</span>
															</div>
														</div>

														<div class="profile-info-row">
															<div class="profile-info-name"> 地址 </div>

															<div class="profile-info-value">
																<i class="fa fa-map-marker light-orange bigger-110"></i>
																<span th:text="${myUser.address}">火星</span>
															</div>
														</div>

														<div class="profile-info-row">
															<div class="profile-info-name"> 电话 </div>

															<div class="profile-info-value">
																<span th:text="${myUser.phone}">11011001100</span>
															</div>
														</div>

														<div class="profile-info-row">
															<div class="profile-info-name"> 邮箱 </div>

															<div class="profile-info-value">
																<span th:text="${myUser.email}">13381231@qq.com</span>
															</div>
														</div>

														<div class="profile-info-row">
															<div class="profile-info-name"> 创建时间 </div>

															<div class="profile-info-value">
																<span th:text="${#dates.format(myUser.createTime,'yyyy-MM-dd')}">2020/5/22</span>
															</div>
														</div>
													</div>

													<div class="hr hr-8 dotted"></div>

													<div class="profile-myUser-info">
														<div class="profile-info-row">
															<div class="profile-info-name"> 个人网站 </div>

															<div class="profile-info-value">
																<a href="http://www.linging.top" target="_blank">www.linging.top</a>
															</div>
														</div>

													</div>
												</div><!-- /.col -->
											</div><!-- /.row -->

											<div class="space-20"></div>

											<div class="row">
												<div class="col-xs-12 col-sm-6">
													<div class="widget-box transparent">
														<div class="widget-header widget-header-small">
															<h4 class="widget-title smaller">
																<i class="ace-icon fa fa-check-square-o bigger-110"></i>
																关于我
															</h4>
														</div>

														<div class="widget-body">
															<div class="widget-main">
																<p>
																	My job is mostly lorem ipsuming and dolor sit ameting as long as consectetur adipiscing elit.
																</p>
																<p>
																	Sometimes quisque commodo massa gets in the way and sed ipsum porttitor facilisis.
																</p>
																<p>
																	The best thing about my job is that vestibulum id ligula porta felis euismod and nullam quis risus eget urna mollis ornare.
																</p>
																<p>
																	Thanks for visiting my profile.
																</p>
															</div>
														</div>
													</div>
												</div>

												<div class="col-xs-12 col-sm-6">
													<div class="widget-box transparent">
														<div class="widget-header widget-header-small header-color-blue2">
															<h4 class="widget-title smaller">
																<i class="ace-icon fa fa-lightbulb-o bigger-120"></i>
																我的技能
															</h4>
														</div>

														<div class="widget-body">
															<div class="widget-main padding-16">
																<div class="clearfix">
																	<div class="grid3 center">
																		<div class="easy-pie-chart percentage" data-percent="45" data-color="#CA5952">
																			<span class="percent">45</span>%
																		</div>

																		<div class="space-2"></div>
																		平面设计
																	</div>

																	<div class="grid3 center">
																		<div class="center easy-pie-chart percentage" data-percent="90" data-color="#59A84B">
																			<span class="percent">90</span>%
																		</div>

																		<div class="space-2"></div>
																		HTML5 & CSS3
																	</div>

																	<div class="grid3 center">
																		<div class="center easy-pie-chart percentage" data-percent="80" data-color="#9585BF">
																			<span class="percent">80</span>%
																		</div>

																		<div class="space-2"></div>
																		Javascript/jQuery
																	</div>
																</div>

																<div class="hr hr-16"></div>

																<div class="profile-skills">
																	<div class="progress">
																		<div class="progress-bar" style="width:80%">
																			<span class="pull-left">HTML5 & CSS3</span>
																			<span class="pull-right">80%</span>
																		</div>
																	</div>

																	<div class="progress">
																		<div class="progress-bar progress-bar-success" style="width:72%">
																			<span class="pull-left">Javascript & jQuery</span>

																			<span class="pull-right">72%</span>
																		</div>
																	</div>

																	<div class="progress">
																		<div class="progress-bar progress-bar-purple" style="width:70%">
																			<span class="pull-left">Java & MySQL</span>

																			<span class="pull-right">70%</span>
																		</div>
																	</div>

																	<div class="progress">
																		<div class="progress-bar progress-bar-warning" style="width:50%">
																			<span class="pull-left">Python</span>

																			<span class="pull-right">50%</span>
																		</div>
																	</div>

																	<div class="progress">
																		<div class="progress-bar progress-bar-danger" style="width:38%">
																			<span class="pull-left">Photoshop</span>

																			<span class="pull-right">38%</span>
																		</div>
																	</div>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
										</div><!-- /#home -->
									</div>
								</div>
							</div>
							</div>
						<!-- PAGE CONTENT ENDS -->
						</div><!-- /.col -->
					</div><!-- /.row -->
				</div><!-- /.page-content-area -->
			</div><!-- /.page-content -->
		</div><!-- /.main-content -->

		<!--页脚	-->
		<div th:replace="_fragment::footer"></div>

		<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
		<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
		</a>
	</div><!-- /.main-container -->

<!-- basic scripts -->

<!--引入js	-->
<th:block th:replace="_fragment::script"></th:block>

<!-- inline scripts related to this page -->
<script type="text/javascript">
jQuery(function($) {

	//editables on first profile page
	$.fn.editable.defaults.mode = 'inline';
	$.fn.editableform.loading = "<div class='editableform-loading'><i class='ace-icon fa fa-spinner fa-spin fa-2x light-blue'></i></div>";
	$.fn.editableform.buttons = '<button type="submit" class="btn btn-info editable-submit"><i class="ace-icon fa fa-check"></i></button>'+
			'<button type="button" class="btn editable-cancel"><i class="ace-icon fa fa-times"></i></button>';

	//editables

	//text editable
	$('#username')
			.editable({
				type: 'text',
				name: 'username'
			});
	//select2 editable
	var countries = [];
	$.each({ "CA": "Canada", "IN": "India", "NL": "Netherlands", "TR": "Turkey", "US": "United States"}, function(k, v) {
		countries.push({id: k, text: v});
	});

	var cities = [];
	cities["CA"] = [];
	$.each(["Toronto", "Ottawa", "Calgary", "Vancouver"] , function(k, v){
		cities["CA"].push({id: v, text: v});
	});
	cities["IN"] = [];
	$.each(["Delhi", "Mumbai", "Bangalore"] , function(k, v){
		cities["IN"].push({id: v, text: v});
	});
	cities["NL"] = [];
	$.each(["Amsterdam", "Rotterdam", "The Hague"] , function(k, v){
		cities["NL"].push({id: v, text: v});
	});
	cities["TR"] = [];
	$.each(["Ankara", "Istanbul", "Izmir"] , function(k, v){
		cities["TR"].push({id: v, text: v});
	});
	cities["US"] = [];
	$.each(["New York", "Miami", "Los Angeles", "Chicago", "Wysconsin"] , function(k, v){
		cities["US"].push({id: v, text: v});
	});

	var currentValue = "NL";
	$('#country').editable({
		type: 'select2',
		value : 'NL',
		//onblur:'ignore',
		source: countries,
		select2: {
			'width': 140
		},
		success: function(response, newValue) {
			if(currentValue == newValue) return;
			currentValue = newValue;

			var new_source = (!newValue || newValue == "") ? [] : cities[newValue];

			//the destroy method is causing errors in x-editable v1.4.6+
			//it worked fine in v1.4.5
			/**
			 $('#city').editable('destroy').editable({
							type: 'select2',
							source: new_source
						}).editable('setValue', null);
			 */

			//so we remove it altogether and create a new element
			var city = $('#city').removeAttr('id').get(0);
			$(city).clone().attr('id', 'city').text('Select City').editable({
				type: 'select2',
				value : null,
				//onblur:'ignore',
				source: new_source,
				select2: {
					'width': 140
				}
			}).insertAfter(city);//insert it after previous instance
			$(city).remove();//remove previous instance

		}
	});

	$('#city').editable({
		type: 'select2',
		value : 'Amsterdam',
		//onblur:'ignore',
		source: cities[currentValue],
		select2: {
			'width': 140
		}
	});



	//custom date editable
	$('#signup').editable({
		type: 'adate',
		date: {
			//datepicker plugin options
			format: 'yyyy/mm/dd',
			viewformat: 'yyyy/mm/dd',
			weekStart: 1

			//,nativeUI: true//if true and browser support input[type=date], native browser control will be used
			//,format: 'yyyy-mm-dd',
			//viewformat: 'yyyy-mm-dd'
		}
	})

	$('#age').editable({
		type: 'spinner',
		name : 'age',
		spinner : {
			min : 16,
			max : 99,
			step: 1,
			on_sides: true
			//,nativeUI: true//if true and browser support input[type=number], native browser control will be used
		}
	});


	$('#login').editable({
		type: 'slider',
		name : 'login',

		slider : {
			min : 1,
			max: 50,
			width: 100
			//,nativeUI: true//if true and browser support input[type=range], native browser control will be used
		},
		success: function(response, newValue) {
			if(parseInt(newValue) == 1)
				$(this).html(newValue + " hour ago");
			else $(this).html(newValue + " hours ago");
		}
	});

	$('#about').editable({
		mode: 'inline',
		type: 'wysiwyg',
		name : 'about',

		wysiwyg : {
			//css : {'max-width':'300px'}
		},
		success: function(response, newValue) {
		}
	});



	// *** editable avatar *** //
	try {//ie8 throws some harmless exceptions, so let's catch'em

		//first let's add a fake appendChild method for Image element for browsers that have a problem with this
		//because editable plugin calls appendChild, and it causes errors on IE at unpredicted points
		try {
			document.createElement('IMG').appendChild(document.createElement('B'));
		} catch(e) {
			Image.prototype.appendChild = function(el){}
		}

		var last_gritter
		$('#avatar').editable({
			type: 'image',
			name: 'avatar',
			value: null,
			image: {
				//specify ace file input plugin's options here
				btn_choose: 'Change Avatar',
				droppable: true,
				maxSize: 110000,//~100Kb

				//and a few extra ones here
				name: 'avatar',//put the field name here as well, will be used inside the custom plugin
				on_error : function(error_type) {//on_error function will be called when the selected file has a problem
					if(last_gritter) $.gritter.remove(last_gritter);
					if(error_type == 1) {//file format error
						last_gritter = $.gritter.add({
							title: 'File is not an image!',
							text: 'Please choose a jpg|gif|png image!',
							class_name: 'gritter-error gritter-center'
						});
					} else if(error_type == 2) {//file size rror
						last_gritter = $.gritter.add({
							title: 'File too big!',
							text: 'Image size should not exceed 100Kb!',
							class_name: 'gritter-error gritter-center'
						});
					}
					else {//other error
					}
				},
				on_success : function() {
					$.gritter.removeAll();
				}
			},
			url: function(params) {
				// ***UPDATE AVATAR HERE*** //
				//for a working upload example you can replace the contents of this function with
				//examples/profile-avatar-update.js

				var deferred = new $.Deferred

				var value = $('#avatar').next().find('input[type=hidden]:eq(0)').val();
				if(!value || value.length == 0) {
					deferred.resolve();
					return deferred.promise();
				}


				//dummy upload
				setTimeout(function(){
					if("FileReader" in window) {
						//for browsers that have a thumbnail of selected image
						var thumb = $('#avatar').next().find('img').data('thumb');
						if(thumb) $('#avatar').get(0).src = thumb;
					}

					deferred.resolve({'status':'OK'});

					if(last_gritter) $.gritter.remove(last_gritter);
					last_gritter = $.gritter.add({
						title: 'Avatar Updated!',
						text: 'Uploading to server can be easily implemented. A working example is included with the template.',
						class_name: 'gritter-info gritter-center'
					});

				} , parseInt(Math.random() * 800 + 800))

				return deferred.promise();

				// ***END OF UPDATE AVATAR HERE*** //
			},

			success: function(response, newValue) {
			}
		})
	}catch(e) {}



	//another option is using modals
	$('#avatar2').on('click', function(){
		var modal =
				'<div class="modal fade">\
				  <div class="modal-dialog">\
				   <div class="modal-content">\
					<div class="modal-header">\
						<button type="button" class="close" data-dismiss="modal">&times;</button>\
						<h4 class="blue">选择一张头像</h4>\
					</div>\
					\
					<form class="no-margin">\
					 <div class="modal-body">\
						<div class="space-4"></div>\
						<div style="width:75%;margin-left:12%;"><input type="file" name="file-input" /></div>\
					 </div>\
					\
					 <div class="modal-footer center">\
						<button type="submit" class="btn btn-sm btn-success"><i class="ace-icon fa fa-check"></i> 保存 </button>\
						<button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> 取消 </button>\
					 </div>\
					</form>\
				  </div>\
				 </div>\
				</div>';


		var modal = $(modal);
		modal.modal("show").on("hidden", function(){
			modal.remove();
		});

		var working = false;

		var form = modal.find('form:eq(0)');
		var file = form.find('input[type=file]').eq(0);
		file.ace_file_input({
			style:'well',
			btn_choose:'点击选择一个新的头像',
			btn_change:null,
			no_icon:'ace-icon fa fa-picture-o',
			thumbnail:'small',
			before_remove: function() {
				//don't remove/reset files while being uploaded
				return !working;
			},
			allowExt: ['jpg', 'jpeg', 'png', 'gif'],
			allowMime: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
		});

		form.on('submit', function(){
			if(!file.data('ace_input_files')) return false;

			file.ace_file_input('disable');
			form.find('button').attr('disabled', 'disabled');
			form.find('.modal-body').append("<div class='center'><i class='ace-icon fa fa-spinner fa-spin bigger-150 orange'></i></div>");

			var deferred = new $.Deferred;
			working = true;
			deferred.done(function() {
				form.find('button').removeAttr('disabled');
				form.find('input[type=file]').ace_file_input('enable');
				form.find('.modal-body > :last-child').remove();

				modal.modal("hide");


				var thumb = file.next().find('img').data('thumb');	//图片的base64
				if(thumb){	//不为空,发送异步请求，保存图片
					console.log(thumb);
					$.ajax({
						type:"post",
						async:true,
						url:'/admin/changeAvatar',
						data:{'avatar':thumb},
						contentType:"application/json",
						dataType:"json",
						success:function (res) {
							console.log(res);
							$('#avatar2').get(0).src = res.url;
							window.location.href = "/admin/toProfile";
						},
						error:function (res) {
							console.log(res);
						}
					});
				}

				//alert("ok");

				working = false;
			});


			setTimeout(function(){
				deferred.resolve();
			} , parseInt(Math.random() * 800 + 800));

			return false;
		});

	});



	//////////////////////////////
	$('#profile-feed-1').ace_scroll({
		height: '250px',
		mouseWheelLock: true,
		alwaysVisible : true
	});

	$('a[ data-original-title]').tooltip();

	$('.easy-pie-chart.percentage').each(function(){
		var barColor = $(this).data('color') || '#555';
		var trackColor = '#E2E2E2';
		var size = parseInt($(this).data('size')) || 72;
		$(this).easyPieChart({
			barColor: barColor,
			trackColor: trackColor,
			scaleColor: false,
			lineCap: 'butt',
			lineWidth: parseInt(size/10),
			animate:false,
			size: size
		}).css('color', barColor);
	});

	///////////////////////////////////////////

	//right & left position
	//show the myUser info on right or left depending on its position
	$('#myUser-profile-2 .memberdiv').on('mouseenter touchstart', function(){
		var $this = $(this);
		var $parent = $this.closest('.tab-pane');

		var off1 = $parent.offset();
		var w1 = $parent.width();

		var off2 = $this.offset();
		var w2 = $this.width();

		var place = 'left';
		if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) place = 'right';

		$this.find('.popover').removeClass('right left').addClass(place);
	}).on('click', function(e) {
		e.preventDefault();
	});


	///////////////////////////////////////////
	$('#myUser-profile-3')
			.find('input[type=file]').ace_file_input({
				style:'well',
				btn_choose:'Change avatar',
				btn_change:null,
				no_icon:'ace-icon fa fa-picture-o',
				thumbnail:'large',
				droppable:true,

				allowExt: ['jpg', 'jpeg', 'png', 'gif'],
				allowMime: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
			})
			.end().find('button[type=reset]').on(ace.click_event, function(){
				$('#myUser-profile-3 input[type=file]').ace_file_input('reset_input');
			})
			.end().find('.date-picker').datepicker().next().on(ace.click_event, function(){
				$(this).prev().focus();
			})
	$('.input-mask-phone').mask('(999) 999-9999');



	////////////////////
	//change profile
	$('[data-toggle="buttons"] .btn').on('click', function(e){
		var target = $(this).find('input[type=radio]');
		var which = parseInt(target.val());
		$('.myUser-profile').parent().addClass('hide');
		$('#myUser-profile-'+which).parent().removeClass('hide');
	});
});
</script>
</body>
</html>
